<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Function polymorphic_relaxed_get</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../variant/reference.html#header.boost.variant.polymorphic_get_hpp" title="Header &lt;boost/variant/polymorphic_get.hpp&gt;">
<link rel="prev" href="bad_polymorphic_get.html" title="Class bad_polymorphic_get">
<link rel="next" href="polymorphic_strict_get.html" title="Function polymorphic_strict_get">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
<td align="center"><a href="../../../index.html">Home</a></td>
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="bad_polymorphic_get.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../variant/reference.html#header.boost.variant.polymorphic_get_hpp"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="polymorphic_strict_get.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="refentry">
<a name="boost.polymorphic_relaxed_get"></a><div class="titlepage"></div>
<div class="refnamediv">
<h2><span class="refentrytitle">Function polymorphic_relaxed_get</span></h2>
<p>boost::polymorphic_relaxed_get — Retrieves a value of a specified type from a given
          <code class="computeroutput"><a class="link" href="variant.html" title="Class template variant">variant</a></code>.Unlike <a class="link" href="polymorphic_strict_get.html" title="Function polymorphic_strict_get">polymorphic_strict_get</a> does not assert at compile time
        that type <code class="computeroutput">U</code> is one of the types that can be stored in variant.</p>
</div>
<h2 class="refsynopsisdiv-title">Synopsis</h2>
<div class="refsynopsisdiv"><pre class="synopsis"><span class="comment">// In header: &lt;<a class="link" href="../variant/reference.html#header.boost.variant.polymorphic_get_hpp" title="Header &lt;boost/variant/polymorphic_get.hpp&gt;">boost/variant/polymorphic_get.hpp</a>&gt;

</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> U<span class="special">,</span> <span class="keyword">typename</span> T1<span class="special">,</span> <span class="keyword">typename</span> T2<span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="keyword">typename</span> TN<span class="special">&gt;</span> 
  <span class="identifier">U</span> <span class="special">*</span> <span class="identifier">polymorphic_relaxed_get</span><span class="special">(</span><a class="link" href="variant.html" title="Class template variant">variant</a><span class="special">&lt;</span><span class="identifier">T1</span><span class="special">,</span> <span class="identifier">T2</span><span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="identifier">TN</span><span class="special">&gt;</span> <span class="special">*</span> operand<span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> U<span class="special">,</span> <span class="keyword">typename</span> T1<span class="special">,</span> <span class="keyword">typename</span> T2<span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="keyword">typename</span> TN<span class="special">&gt;</span> 
  <span class="keyword">const</span> <span class="identifier">U</span> <span class="special">*</span> <span class="identifier">polymorphic_relaxed_get</span><span class="special">(</span><span class="keyword">const</span> <a class="link" href="variant.html" title="Class template variant">variant</a><span class="special">&lt;</span><span class="identifier">T1</span><span class="special">,</span> <span class="identifier">T2</span><span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="identifier">TN</span><span class="special">&gt;</span> <span class="special">*</span> operand<span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> U<span class="special">,</span> <span class="keyword">typename</span> T1<span class="special">,</span> <span class="keyword">typename</span> T2<span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="keyword">typename</span> TN<span class="special">&gt;</span> 
  <span class="identifier">U</span> <span class="special">&amp;</span> <span class="identifier">polymorphic_relaxed_get</span><span class="special">(</span><a class="link" href="variant.html" title="Class template variant">variant</a><span class="special">&lt;</span><span class="identifier">T1</span><span class="special">,</span> <span class="identifier">T2</span><span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="identifier">TN</span><span class="special">&gt;</span> <span class="special">&amp;</span> operand<span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> U<span class="special">,</span> <span class="keyword">typename</span> T1<span class="special">,</span> <span class="keyword">typename</span> T2<span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="keyword">typename</span> TN<span class="special">&gt;</span> 
  <span class="keyword">const</span> <span class="identifier">U</span> <span class="special">&amp;</span> <span class="identifier">polymorphic_relaxed_get</span><span class="special">(</span><span class="keyword">const</span> <a class="link" href="variant.html" title="Class template variant">variant</a><span class="special">&lt;</span><span class="identifier">T1</span><span class="special">,</span> <span class="identifier">T2</span><span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="identifier">TN</span><span class="special">&gt;</span> <span class="special">&amp;</span> operand<span class="special">)</span><span class="special">;</span></pre></div>
<div class="refsect1">
<a name="id-1.3.44.5.11.4.4"></a><h2>Description</h2>
<p>The <code class="computeroutput">polymorphic_get</code> function allows run-time checked,
          type-safe retrieval of the content of the given
          <code class="computeroutput"><a class="link" href="variant.html" title="Class template variant">variant</a></code>. The function succeeds
          only if the content is of the specified type <code class="computeroutput">U</code> or of type
          derived from type <code class="computeroutput">U</code>, with
          failure indicated as described below.</p>
<p><span class="bold"><strong>Recomendation</strong></span>: Use
          <code class="computeroutput"><a class="link" href="polymorphic_get.html" title="Function polymorphic_get">polymorphic_get</a></code> or <code class="computeroutput"><a class="link" href="polymorphic_strict_get.html" title="Function polymorphic_strict_get">polymorphic_strict_get</a></code>
          in new code.
          <code class="computeroutput"><a class="link" href="polymorphic_strict_get.html" title="Function polymorphic_strict_get">polymorphic_strict_get</a></code>
          provides more compile time checks and its behavior is closer to <code class="computeroutput">std::get</code>
          from C++ Standard Library.</p>
<p><span class="bold"><strong>Warning</strong></span>: After either
          <code class="computeroutput">operand</code> or its content is destroyed (e.g., when the
          given <code class="computeroutput"><a class="link" href="variant.html" title="Class template variant">variant</a></code> is assigned a
          value of different type), the returned reference is invalidated.
          Thus, significant care and caution must be extended when handling
          the returned reference.</p>
<div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term">Notes:</span></p></td>
<td>As part of its guarantee of type-safety, <code class="computeroutput">polymorphic_get</code>
        enforces <code class="computeroutput">const</code>-correctness. Thus, the specified type
        <code class="computeroutput">U</code> must be <code class="computeroutput">const</code>-qualified whenever
        <code class="computeroutput">operand</code> or its content is likewise
        <code class="computeroutput">const</code>-qualified. The converse, however, is not required:
        that is, the specified type <code class="computeroutput">U</code> may be
        <code class="computeroutput">const</code>-qualified even when <code class="computeroutput">operand</code> and its
        content are not.</td>
</tr>
<tr>
<td><p><span class="term">Returns:</span></p></td>
<td>If passed a pointer, <code class="computeroutput">polymorphic_get</code> returns a pointer to
        the value content if it is of the specified type <code class="computeroutput">U</code> or of type
        derived from type <code class="computeroutput">U</code>;
        otherwise, a null pointer is returned. If passed a reference,
        <code class="computeroutput">polymorphic_get</code> returns a reference to the value content if it is of
        the specified type <code class="computeroutput">U</code>  or of type
          derived from type <code class="computeroutput">U</code>; otherwise, an exception is thrown
        (see below).</td>
</tr>
<tr>
<td><p><span class="term">Throws:</span></p></td>
<td>Overloads taking a
        <code class="computeroutput"><a class="link" href="variant.html" title="Class template variant">variant</a></code> pointer will not
        throw; the overloads taking a
        <code class="computeroutput"><a class="link" href="variant.html" title="Class template variant">variant</a></code> reference throw
        <code class="computeroutput"><a class="link" href="bad_polymorphic_get.html" title="Class bad_polymorphic_get">bad_polymorphic_get</a></code> if the content is not of
        the specified type <code class="computeroutput">U</code>or of type
        derived from type <code class="computeroutput">U</code>.</td>
</tr>
<tr>
<td><p><span class="term">Rationale:</span></p></td>
<td>While visitation via
        <code class="computeroutput"><a class="link" href="apply_visitor.html" title="Function apply_visitor">apply_visitor</a></code>
        is generally preferred due to its greater safety, <code class="computeroutput">polymorphic_get</code> may
        may be more convenient in some cases due to its straightforward
        usage.</td>
</tr>
</tbody>
</table></div>
</div>
</div>
<div class="copyright-footer">Copyright © 2002, 2003 Eric Friedman, Itay Maman<br>Copyright © 2014-2024 Antony Polukhin<p>Distributed under the Boost Software License, Version 1.0.
    (See accompanying file <code class="filename">LICENSE_1_0.txt</code> or copy at 
    <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
    </p>
</div>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="bad_polymorphic_get.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../variant/reference.html#header.boost.variant.polymorphic_get_hpp"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="polymorphic_strict_get.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
